package com.flong.desgin.patterns.openclose.improve;

import lombok.var;

/**
 * @Author:liangjl
 * @Date: 2020/3/7-21:42
 * @Eamil:jilongliang@sina.com
 * @Description: 开闭原则
 */
public class Ocp {

    public static void main(String[] args) {
        var graphicEditor = new GraphicEditor();
        graphicEditor.grawShape(new Rectangle());
        graphicEditor.grawShape(new Circle());
        graphicEditor.grawShape(new Triangle());
    }
}

class GraphicEditor {
    public void grawShape(Shape shape) {
        shape.draw();
    }

}

abstract class Shape {
    //public int m_type;
    //抽象方法
    public abstract void draw();
}

class Rectangle extends Shape {
    Rectangle() {
        //super.m_type = 1;
    }


    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}

class Circle extends Shape {
    Circle() {
       // super.m_type = 2;
    }

    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

class Triangle extends Shape {
    Triangle() {
       // super.m_type = 3;
    }

    @Override
    public void draw() {
        System.out.println("绘制三角形");
    }
}